/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.revdev.llt.bean.entities;

import de.revdev.llt.bean.entities.interfaces.EntityInterface;
import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author f.lindermaier
 */
@Entity
@Table(name = "tbl_category")
public class Category implements Serializable, EntityInterface {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String name;
    private String description;
    @ManyToOne
    @JoinColumn(name = "id_overCategory")
    private Category overCategory;
    @OneToMany(mappedBy = "overCategory", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    private List<Category> underCategories;

    @Override
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Category getOverCategory() {
        return overCategory;
    }

    public void setOverCategory(Category overCategory) {
        this.overCategory = overCategory;
    }

    public List<Category> getUnderCategories() {
        return underCategories;
    }

    public void setUnderCategories(List<Category> underCategories) {
        this.underCategories = underCategories;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Category)) {
            return false;
        }
        Category other = (Category) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "de.revdev.llt.bean.entities.Category[ id=" + id + " ]";
    }
}
